﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameController : MonoBehaviour
{


    public bool IsPlayerDeath;
    private GameObject player;
    private CharacterBase playerBase;

    private void Start()
    {
        IsPlayerDeath = false;
        player = GameObject.Find("Player");
        playerBase = GameObject.Find("Base").GetComponent<CharacterBase>();
    }

    void Update ()
    {
        PlayerDeathTest();
        if(IsPlayerDeath)
        {
            MonsterBase.SetBuff();
            GameObject.Find("Player").SetActive(false);
            UIManager.Instance.OpenUI("Death");
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!Data.Instance.TheGameState.isPaused)
            {
                UIManager.Instance.OpenUI("PauseMenu");
                Time.timeScale = 0;
                Data.Instance.TheGameState.isPaused = true;
            }
            else
            {
                UIManager.Instance.CloseUI("PauseMenu");
                Time.timeScale = 1;
                Data.Instance.TheGameState.isPaused = false;
            }
        }
	}

    /// <summary>
    /// 检测玩家是否死亡
    /// </summary>
    void PlayerDeathTest()
    {
        if(player.transform.position.y<=-9)
        {
            if(!IsPlayerDeath)
            {
                AudioController.Play("playerfallendeath");
            }

            IsPlayerDeath = true;
        }//死因：掉落地图之外

        if(playerBase.health<=0)
        {
            IsPlayerDeath = true;
        }//死因：太菜
    }
}
